package cn.epsilon3.utils;

import cn.hutool.core.util.StrUtil;
import cn.epsilon3.domain.e3.vo.E3ResourceVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @description 集合工具类
 *
 * @author: epsilon3
 * @date: 2023/9/8 16:07
 */

public class CollectionsUtils {

    /**
     * 树形菜单转换
     *
     * @param dataList 原始资源list
     * @param parentId 父级id 默认为0
     * @return 树级菜单list
     */
    public static List<E3ResourceVO> generateResourceTree(List<E3ResourceVO> dataList, String parentId) {
         return dataList.stream()
                .filter(parent -> StrUtil.equals(parentId,parent.getParentId()))
                .peek(child -> child.setChildren(generateResourceTree(dataList,child.getResourceId())))
                .collect(Collectors.toList());
    }
}
